package org.ecpkn.PAGridSim.core.gridsimEntity.policy.paPolicy.priority.EDF;

import gridsim.ResGridlet;

import java.util.Comparator;

import org.ecpkn.PAGridSim.core.tasksCreation.Job;

public class ComparatorDeadline implements Comparator<ResGridlet> {

	public int compare(ResGridlet rgl0,ResGridlet rgl1) {
		
		Job job0=(Job)rgl0.getGridlet();
		Job job1=(Job)rgl1.getGridlet();

		// deadline first,then execution time
		int flagDeadline = 0;
		double deadline0 = job0.getDeadline_();
		double deadline1 = job1.getDeadline_();
		flagDeadline = (int) (deadline0-deadline1);
		if (flagDeadline == 0) {
			int flagLength = 0;
			double length0 = job0.getGridletLength();
			double length1 = job1.getGridletLength();
			flagLength =(int) (length0-length1);
			return flagLength;
		} else {
			return flagDeadline;
		}
	}

}
